import request from 'umi-request';

export async function queryRule(params = {}) {
  return request('/hr-ssc/api/api-admin/newEmployees/list', {
    method: 'get',
    params: {
      pageNum: params.current,
      pageSize: params.pageSize,
      keyword: params.keyword,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getEmployeeById(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/getEmployeeById/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}


export async function deleteEmployeeById(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/deleteMainInfo/${id}`, {
    method: 'get',
  });
}


export async function getEducationInfo(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/getEduByOid/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function addEducationInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/saveEducationInfo', {
    method: 'POST',
    data: params,
  });
}

export async function updateEducationInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/updateEducationInfo', {
    method: 'POST',
    data: params,
  });
}

export async function deleteEducationInfo(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/deleteEducation/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function getSocietyInfo(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/getSocietyInfo/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function addSocietyInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/saveSociety', {
    method: 'POST',
    data: params,
  });
}

export async function updateSocietyInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/updateSociety', {
    method: 'POST',
    data: params,
  });
}

export async function deleteSocietyInfo(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/deleteSociety/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function getFamilyInfo(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/getFamilyListByOid/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function addFamilyInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/saveFamily', {
    method: 'POST',
    data: params,
  });
}

export async function updateFamilyInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/updateFamily', {
    method: 'POST',
    data: params,
  });
}

export async function deleteFamilyInfo(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/deleteFamily/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function getInorgInfo(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/getInorgInfo/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function addInorgInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/saveInorgInfo', {
    method: 'POST',
    data: params,
  });
}

export async function updateInorgInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/updateInorgInfo', {
    method: 'POST',
    data: params,
  });
}

export async function deleteInorgInfo(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/deleteInorg/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function getJobByOrgId(id) {
  return request(`/hr-ssc/api/api-admin/job/findJobByOrgId/${id}`, {
    method: 'get'
  }).then((res) => {
    return res.data;
  });
}

export async function getBaseOptions() {
  return request(`/hr-ssc/api/api-admin/job/getBaseItem`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function getNativeplace() {
  return request(`/hr-ssc/api/api-admin/job/getNativeplace`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function updateMainInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/updateMainInfo', {
    method: 'POST',
    data: params,
  });
}

export async function findTiaoxinTixiByJobId(id) {
  return request(`/hr-ssc/api/api-admin/job/findTiaoxinTixiByJobId/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function updateHireDate(oid,date,newDate) {
  return request('/hr-ssc/api/api-admin/userUpdateInfo/saveUserUpdateHiredateInfo', {
    method: 'POST',
    data: {
      oid:oid,
      hiredate:date,
      newHiredate:newDate
    },
    requestType: "form"
  });
}

export async function findDictionary(code) {
  return request(`/hr-ssc/api/api-admin/neusoft/findDictionary`, {
    method: 'get',
    params: {
      typeCode:code
    }
  }).then((res) => {
    return res.data;
  });
}


export async function queryInternalPage(oid) {
  return request(`/hr-ssc/api/api-admin/newEmployees/getInternalAward/${oid}`, {
    method: 'get',
    params:{
      pageNum: 1,
      pageSize: 100,
    }
  }).then((res) => {
    return {
      data:res.data
    };
  });
}

export async function saveInternalAward(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/saveInternalAward', {
    method: 'POST',
    data: params,
  });
}

export async function updateInternalAward(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/updateInternalAward', {
    method: 'POST',
    data: params,
  });
}

export async function deleteInternalAward(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/deleteInternalAward/${id}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}
